package com.luoye.lj.platform.service;

import com.luoye.lj.util.ClassFinder;
import com.luoye.lj.util.mvc.annotation.OperateLog;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/*
 * Created with IntelliJ IDEA.
 * User: Dave Liu
 * Date: 2016/6/28
 * Time: 16:32
 * To change this template use File | Settings | File Templates.
 */
public class OperationNameGetter {
    public List<String> getAllOperationNames(){
        ClassFinder classFinder=new ClassFinder();
        List<String> classList=classFinder.findAllClass("com.luoye.lj");

        Set<String> operationNameSet=new HashSet<>();

        for(String className:classList){
            try {
                Class clazz=Class.forName(className);
                Method[] methods=clazz.getMethods();
                for (Method method:methods){
                    if (method.isAnnotationPresent(OperateLog.class)) {
                        OperateLog operateLog = method.getAnnotation(OperateLog.class);
                        operationNameSet.add(operateLog.value());
                    }
                }
            } catch (ClassNotFoundException e) {
            }
        }

        return new ArrayList<String>(operationNameSet);
    }
}
